package myservice.android.utilities;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

public class SearchRunnable implements Runnable {
	
	private Context context;
	private LinearLayout list;
	private ListRow row;
	private TextView label;
	private int count;

	public SearchRunnable(Context context, LinearLayout list, ListRow row, TextView label, int count) {
		
		this.context = context;
		this.list = list;
		this.row = row;		
		this.label = label;
		this.count = count;
		
	}
	
	private View getHorizontalLine() {
		View horizontalLine = new View(context);
		horizontalLine.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,1));
		horizontalLine.setBackgroundColor(0xFF333333);
		return horizontalLine;
	}		
	
	@Override
	public void run() {
		
		if (list.getChildCount() == 0)
    		list.addView(getHorizontalLine());
		
		list.addView(row);    		    		
		list.addView(getHorizontalLine());
		
		// Replace the number in the label with the new count
		label.setText(label.getText().toString().replaceAll("[0-9]+", ""+count));
		
	}

}
